﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Shop_ShopSaleDetail_List2 : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReadAction();

        if (!IsPostBack)
        {
            BindData();
        }
    }

    protected void g_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            DataRow dr = drv.Row;

            string OrderNo = dr["OrderNo"].ToString();
            string CustomerName = dr["CustomerName"].ToString();

            LinkButton lbOrderNo = (LinkButton)e.Item.Cells[2].FindControl("lbOrderNo");                //单据编号
            lbOrderNo.Text = OrderNo;

            Label lbCustomerName = (Label)e.Item.Cells[3].FindControl("lbCustomerName");      //消费者
            lbCustomerName.Text = CustomerName;     
        }
    }

    protected void g_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        string CustomerID = e.Item.Cells[0].Text;

        if (e.CommandName == "OrderNo")             //单据编号 
        {
            Response.Write("<script> parent.parent.AddTab('ShoppingOrder_Search','单据查询','Shop/Order_Manager.aspx');</script>");
        }
        //else if (e.CommandName == "CustomerName")   //消费者信息
        //{
        //    Response.Write("<script> parent.parent.AddTab('CustomerName','会员信息','BalanceCenter/AdminUserEdit.aspx?id=" + CustomerID + "');</script>");
        //}
    }

    /// <summary>
    /// 获取上个页面传过来的值(string ShopID,string Day)
    /// </summary>
    private void ReadAction()
    {
        this.hShopID.Value = Shove._Web.Utility.GetRequest("ShopID");
        this.hGooDID.Value = Shove._Web.Utility.GetRequest("GoodID");

        try
        {
            String StartDay = Shove._Web.Utility.GetRequest("StartDay");
            StartDay = Shove._Convert.StrToDateTime(StartDay, "1900-12-12").ToString("yyyy-MM-dd");

            this.hStartDay.Value = StartDay;
        }
        catch { }

        try
        {
            String EndDay = Shove._Web.Utility.GetRequest("EndDay");
            EndDay = Shove._Convert.StrToDateTime(EndDay, "1900-12-12").ToString("yyyy-MM-dd");

            this.hEndDay.Value = EndDay;
        }
        catch { }
    }

    /// <summary>
    /// 数据梆定
    /// </summary>
    private void BindData()
    {
        DataSet ds = null;

        long ShopID = Shove._Convert.StrToLong(this.hShopID.Value, 0);              //店铺ID  
        long GoodID = Shove._Convert.StrToLong(this.hGooDID.Value, 0);              //商品ID
        string SaleStart = this.hStartDay.Value;
        string SaleEnd = this.hEndDay.Value;            

        try
        {
            DAL.Procedures.P_Site_SalesGoodDetail2(ref ds, SaleStart, SaleEnd, ShopID, GoodID);
            this.BindDetail(ds);
        }
        catch { }
    }

    /// <summary>
    /// 梆定该单据的所有明细
    /// </summary>
    /// <param name="ds"></param>
    private void BindDetail(DataSet ds)
    {
        DataTable dt = null;

        try
        {
            dt = ds.Tables[0];
        }
        catch { }

        if (dt != null && dt.Rows.Count > 0)
        {
            UWGDetail.DataSource = dt;
            UWGDetail.DataBind();
        }

    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }
}
